﻿@using MvcApplication4.Models
@model IEnumerable<tb_Funcionario>

@{
    ViewBag.Title = "Funcionários Cadastrados";
    //Layout = "~/Views/Shared/_Layout.cshtml";
    Layout = "~/Views/Shared/LayouytTeste.cshtml";
}

<h2>Funcionários Cadastrados</h2>
<br/>
    @Html.ActionLink("Cadastrar Funcionário", "Create", "CadastroFuncionario")
<br/>
<br/>

    @{
        Html.Syncfusion().Grid<tb_Funcionario>("GenericListGrid")
            .Datasource(Model)
            .Caption("Funcionarios Cadastrados")
            .EnablePaging()
            .EnableSorting()
            .EnableFiltering()
            .AutoFormat(Skins.Turquoise)
            .AllowResizing(true)
            .ClientSideEvents(e => e.OnToolbarClickEvent("pdf_export"))
            .ToolBar(toolbar =>
                        {
                            toolbar.Add(GridToolBarItems.ExcelExport, "Excel")
                                   .Add(GridToolBarItems.WordExport, "Word")
                                   .Add(GridToolBarItems.PDFExport, "PDF");
                        })
            .Mappers(map =>
            {
                map.ExportExcelAction("ExportToExcel")
                   .ExportWordAction("ExportToWord")
                   .ExportPdfAction("ExportToPDF");
            })
           // .AllowAutoWrap(true)
           // .ResizeSettings(resize =>
           //{
           //    resize.ResizeToFit(true);
           //    resize.ClipContent(true);
           //})
            .Column(cols =>
                {
                    cols.Add(c => c.ID_Funcionario).HeaderText("ID").TextAlign(Syncfusion.Mvc.Grid.TextAlignment.Right).Width(40);
                    cols.Add(c => c.tb_UBS.Nome_UBS).HeaderText("Nome UBS").Width(100);
                    cols.Add(c => c.Nome_Funcionario).HeaderText("Nome Funcionário").Width(100);
                    cols.Add(c => c.CPF).HeaderText("CPF").Width(80);
                    cols.Add(c => c.Login_Fun).HeaderText("Login").Width(80);
                    cols.Add(c => c.Telefone).HeaderText("Telefone").Width(90);
                    cols.Add(c => c.Email).HeaderText("Email").Width(130);
                    cols.Add("Editar").HeaderText("Editar?").Format("<a href=/CadastroFuncionario/Edit/{ID_Funcionario}>Editar</a>").Width(50);
                    cols.Add("Deletar").HeaderText("Deletar?").Format("<a href=/CadastroFuncionario/Delete/{ID_Funcionario}>Deletar</a>").Width(60);
                }).Render();
    }
    
    
    <script type="text/javascript">

        function pdf_export(sender, args) {



            if (args._currentItemId == sender._ID + 'pdf_export'

            || args._currentItemId == sender._ID + 'word_export'

            || args._currentItemId == sender._ID + 'excel_export') {

                var _VisibleColumns = new Array();

                $.each(sender.get_VisibleColumns(), function (index, Column) {

                    if (Column.Name == "Editar") {

                        Column.Visible = false; //removing columns for export

                    }

                    if (Column.Name == "Deletar") {

                        Column.Visible = false; //removing columns for export

                    }

                    if (Column.Visible == true) {

                        _VisibleColumns.push(Column); //visible columns

                    }

                });

                sender.set_VisibleColumns(Sys.Serialization.JavaScriptSerializer.serialize(_VisibleColumns)); //Set visible columns.

            }

        }

 

</script>